package job._20240322meituan;

import util.LinkList;
import util.ListNode;

/**
 * @Project : algorithm-learning-java
 * @Author : Ruoyu Wang
 * @User : Momenta
 * @DateTime : 2024/3/22 17:37
 */

// 合并链表
public class Q1 {
    public static void main(String[] args) {
        ListNode l1 = LinkList.createList(new int[]{1, 2, 3, 4});
        ListNode l2 = LinkList.createList(new int[]{5, 6, 7, 8});
        ListNode h = new ListNode(-1, null);
        ListNode p = h;
        while (l1 != null && l2 != null) {
            if (l1.val <= l2.val) {
                p.next = l1;
                l1 = l1.next;
            } else {
                p.next = l2;
                l2 = l2.next;
            }
            p = p.next;
        }
        if (l1 == null) {
            p.next = l2;
        }
        if (l2 == null) {
            p.next = l1;
        }
        LinkList.printList(h.next);
    }
}
